<template>
  <view class="container" style="background-color: rgb(246, 246, 246);">
    <dp-userinfo :mylist="mylist"></dp-userinfo>
    <dp-menu :mylist="mylist"></dp-menu>

  </view>
</template>

<script>
import {editWechat} from "../../utils/api/basics";

export default {
  data() {
    return {
      mylist: [],
    }
  },
  computed: {
    imgurl() {
      return getApp().globalData.imgUrl
    },

  },
  onShareTimeline(res) {
    let name = getApp().globalData.name
    let share = {
      title: name,
      path: `/pages/home/home`,
    }
    let logo = getApp().globalData.logoUrl
    if (logo) {
      share.imageUrl = this.imgurl + logo
    }
    return share
  },
  onShareAppMessage(res) {
    let name = getApp().globalData.name
    let share = {
      title: name,
      path: `/pages/home/home`,
    }
    let logo = getApp().globalData.logoUrl

    if (logo) {
      share.imageUrl = this.imgurl + logo
    }
    return share
  },
  onShow() {
    if (!getApp().checkLogin()) { // 假设checkLogin()是你用来检查登录状态的函数
      // 获取当前页面栈
      let pages = getCurrentPages();
      // 获取当前页面
      let currentPage = pages[pages.length - 1];
      // 获取页面路径
      let pagePath = currentPage.route;
      uni.redirectTo({
        url: '/pages/login/login?geturl=' + pagePath
      });
    }
    this.wechatuserlistfun()
  },

  methods: {
    wechatuserlistfun() {
      this.mylist = uni.getStorageSync('useinfo')
      if (!this.mylist.userName || !this.mylist.wxProfileImg) {
        uni.getUserInfo({
          success: (res) => {
            console.log('info', res)
            this.mylist.userName = res.userInfo.nickName
            this.mylist.wxProfileImg = res.userInfo.avatarUrl
            uni.setStorageSync('useinfo', this.mylist)
            editWechat(this.mylist).then(res => {
              if (res.data.code == 200) {
                console.log(res)
              }
            })
          }
        })
      }

    }
  }

}
</script>

<style lang="less">
.xieyibox {
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 99;
  background: rgba(0, 0, 0, 0.7)
}

.xieyibox-content {
  width: 90%;
  margin: 0 auto;
  height: 80%;
  margin-top: 10%;
  background: #fff;
  color: #333;
  padding: 5px 10px 50px 10px;
  position: relative;
  border-radius: 2px
}
</style>